from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-24 14:02:33.498940
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 24, Jul, 2022
Time: 14:02:39
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.9037
Nobs: 727.000 HQIC: -50.2526
Log likelihood: 9152.37 FPE: 1.20336e-22
AIC: -50.4718 Det(Omega_mle): 1.06414e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299915 0.056829 5.278 0.000
L1.Burgenland 0.106947 0.037229 2.873 0.004
L1.Kärnten -0.106967 0.019741 -5.418 0.000
L1.Niederösterreich 0.209062 0.077998 2.680 0.007
L1.Oberösterreich 0.107808 0.076020 1.418 0.156
L1.Salzburg 0.253749 0.039832 6.371 0.000
L1.Steiermark 0.042397 0.051971 0.816 0.415
L1.Tirol 0.108390 0.042153 2.571 0.010
L1.Vorarlberg -0.062909 0.036385 -1.729 0.084
L1.Wien 0.046778 0.067260 0.695 0.487
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054765 0.118736 0.461 0.645
L1.Burgenland -0.031325 0.077786 -0.403 0.687
L1.Kärnten 0.047090 0.041247 1.142 0.254
L1.Niederösterreich -0.177628 0.162967 -1.090 0.276
L1.Oberösterreich 0.410119 0.158835 2.582 0.010
L1.Salzburg 0.288279 0.083224 3.464 0.001
L1.Steiermark 0.107413 0.108587 0.989 0.323
L1.Tirol 0.311259 0.088073 3.534 0.000
L1.Vorarlberg 0.025754 0.076023 0.339 0.735
L1.Wien -0.028468 0.140532 -0.203 0.839
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188149 0.029067 6.473 0.000
L1.Burgenland 0.089724 0.019042 4.712 0.000
L1.Kärnten -0.008758 0.010097 -0.867 0.386
L1.Niederösterreich 0.263575 0.039895 6.607 0.000
L1.Oberösterreich 0.138631 0.038883 3.565 0.000
L1.Salzburg 0.045747 0.020373 2.245 0.025
L1.Steiermark 0.020450 0.026583 0.769 0.442
L1.Tirol 0.092823 0.021561 4.305 0.000
L1.Vorarlberg 0.057103 0.018611 3.068 0.002
L1.Wien 0.113684 0.034403 3.305 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111136 0.029576 3.758 0.000
L1.Burgenland 0.045752 0.019376 2.361 0.018
L1.Kärnten -0.014003 0.010274 -1.363 0.173
L1.Niederösterreich 0.188991 0.040594 4.656 0.000
L1.Oberösterreich 0.301985 0.039564 7.633 0.000
L1.Salzburg 0.109474 0.020730 5.281 0.000
L1.Steiermark 0.104443 0.027048 3.861 0.000
L1.Tirol 0.105662 0.021938 4.816 0.000
L1.Vorarlberg 0.068442 0.018937 3.614 0.000
L1.Wien -0.022529 0.035005 -0.644 0.520
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130432 0.053893 2.420 0.016
L1.Burgenland -0.049877 0.035306 -1.413 0.158
L1.Kärnten -0.040807 0.018722 -2.180 0.029
L1.Niederösterreich 0.165619 0.073969 2.239 0.025
L1.Oberösterreich 0.141264 0.072094 1.959 0.050
L1.Salzburg 0.288959 0.037775 7.650 0.000
L1.Steiermark 0.036178 0.049287 0.734 0.463
L1.Tirol 0.163105 0.039976 4.080 0.000
L1.Vorarlberg 0.099539 0.034506 2.885 0.004
L1.Wien 0.067870 0.063786 1.064 0.287
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055567 0.042872 1.296 0.195
L1.Burgenland 0.039198 0.028086 1.396 0.163
L1.Kärnten 0.051345 0.014893 3.448 0.001
L1.Niederösterreich 0.218005 0.058842 3.705 0.000
L1.Oberösterreich 0.296772 0.057350 5.175 0.000
L1.Salzburg 0.043625 0.030050 1.452 0.147
L1.Steiermark 0.001074 0.039208 0.027 0.978
L1.Tirol 0.142566 0.031801 4.483 0.000
L1.Vorarlberg 0.072705 0.027449 2.649 0.008
L1.Wien 0.079943 0.050742 1.575 0.115
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175146 0.051252 3.417 0.001
L1.Burgenland -0.003280 0.033576 -0.098 0.922
L1.Kärnten -0.062550 0.017804 -3.513 0.000
L1.Niederösterreich -0.082238 0.070344 -1.169 0.242
L1.Oberösterreich 0.194142 0.068560 2.832 0.005
L1.Salzburg 0.057798 0.035923 1.609 0.108
L1.Steiermark 0.235178 0.046871 5.018 0.000
L1.Tirol 0.498372 0.038016 13.109 0.000
L1.Vorarlberg 0.045224 0.032815 1.378 0.168
L1.Wien -0.055450 0.060660 -0.914 0.361
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172757 0.058875 2.934 0.003
L1.Burgenland -0.007410 0.038570 -0.192 0.848
L1.Kärnten 0.066036 0.020452 3.229 0.001
L1.Niederösterreich 0.205191 0.080806 2.539 0.011
L1.Oberösterreich -0.070134 0.078757 -0.891 0.373
L1.Salzburg 0.207337 0.041266 5.024 0.000
L1.Steiermark 0.122211 0.053842 2.270 0.023
L1.Tirol 0.071618 0.043671 1.640 0.101
L1.Vorarlberg 0.117428 0.037695 3.115 0.002
L1.Wien 0.117116 0.069682 1.681 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361829 0.033937 10.662 0.000
L1.Burgenland 0.006943 0.022232 0.312 0.755
L1.Kärnten -0.023648 0.011789 -2.006 0.045
L1.Niederösterreich 0.217835 0.046579 4.677 0.000
L1.Oberösterreich 0.200209 0.045398 4.410 0.000
L1.Salzburg 0.042792 0.023787 1.799 0.072
L1.Steiermark -0.014435 0.031036 -0.465 0.642
L1.Tirol 0.104738 0.025173 4.161 0.000
L1.Vorarlberg 0.070368 0.021729 3.239 0.001
L1.Wien 0.035491 0.040166 0.884 0.377
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039793 0.139240 0.190761 0.150640 0.117586 0.103261 0.062164 0.216141
Kärnten 0.039793 1.000000 -0.006810 0.132585 0.038813 0.094468 0.433177 -0.053863 0.097755
Niederösterreich 0.139240 -0.006810 1.000000 0.333957 0.141652 0.293982 0.096609 0.176977 0.315701
Oberösterreich 0.190761 0.132585 0.333957 1.000000 0.227790 0.324720 0.175230 0.164330 0.260449
Salzburg 0.150640 0.038813 0.141652 0.227790 1.000000 0.142170 0.111614 0.143882 0.123541
Steiermark 0.117586 0.094468 0.293982 0.324720 0.142170 1.000000 0.146250 0.137302 0.071298
Tirol 0.103261 0.433177 0.096609 0.175230 0.111614 0.146250 1.000000 0.112051 0.143081
Vorarlberg 0.062164 -0.053863 0.176977 0.164330 0.143882 0.137302 0.112051 1.000000 -0.001178
Wien 0.216141 0.097755 0.315701 0.260449 0.123541 0.071298 0.143081 -0.001178 1.000000